import echarts from 'echarts'
//echarts实例案例代码  
//   https://github.com/nickiwen/echarts
const install =function(Vue){
    Object.defineProperties(Vue.prototype,{
        $charts:{
            get(){
                return{
                    chinaMap:function(id,data){
                        var dom = document.getElementById(id);
                        var myChart = echarts.init(dom);
                        var option = {
                            height:240,
                            tooltip:{
                                triggerOn:"click",
                                enterable:true,
                                formatter(data){
                                    return '<a href="/city/'+data.data.name+'" style="color:#fff"}><div><p>'+data.data.name+'</p><p>昨日确诊：'+data.data.value+'</p></div></a>'
                                }
                            },
                            visualMap:[{        //设置映射
                                type:'piecewise',
                                pieces:[
                                    {min:0,max:0,color:'#FFFFFF'},
                                    {min:0,max:10,color:'#FDFDCF'},
                                    {min:10,max:100,color:'#FE9E83'},
                                    {min:100,max:1000,color:'#E55A4E'},
                                    {min:1000,max:15000,color:'#47070D'},
                                ]
                            }],
                            series: [{
                                name: '省',
                                type: 'map',
                                map: 'china',
                                roam: true,         //允许自动缩放
                                zoom: 1.2,          //地图缩放比例
                                aspectScale: 0.75,  //
                                label: {            //记录字体
                                    normal: {
                                        show: true,
                                        textStyle: {
                                            color: 'rgba(0,0,0,0.4)'
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        areaColor: 'rgba(0,255,236,0)',
                                        borderColor: 'rgba(0,0,0,0.2)',
                                    },
                                    emphasis: {
                                        areaColor: 'rgba(255,180,0,0.8)',
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        shadowBlur: 20,
                                        borderWidth: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                                data:data,
                            }]
                        };
                        myChart.setOption(option);
                    },
                    worldMap:function(id){
                        var myEcharts = echarts.init(document.getElementById(id));
                        var option = {
                            width:390,
                            height:240,
                            tooltip:{
                                formatter(data){
                                    return '<div><p>'+data.data.name+'</p><p>现存确诊：'+data.data.value+'</p></div>'
                                }
                            },
                            visualMap:[{        //设置映射
                                type:'piecewise',
                                pieces:[
                                    {min:0,max:0,color:'#FFFFFF'},
                                    {min:0,max:10,color:'#FDFDCF'},
                                    {min:10,max:100,color:'#FE9E83'},
                                    {min:100,max:1000,color:'#E55A4E'},
                                    {min:1000,max:10000,color:'#47070D'},
                                ]
                            }],
                            series: [{
                                name: '世界地图',
                                type: 'map',
                                map: 'world',
                                roam: true,         //允许自动缩放
                                zoom: 1.2,          //地图缩放比例
                                aspectScale: 0.75,  //
                                label: {            //记录字体
                                    normal: {
                                        show: true,
                                        textStyle: {
                                            color: 'rgba(0,0,0,0.4)'
                                        }
                                    }
                                },
                                itemStyle: {
                                    normal: {
                                        areaColor: 'rgba(0,255,236,0)',
                                        borderColor: 'rgba(0,0,0,0.2)',
                                    },
                                    emphasis: {
                                        areaColor: 'rgba(255,180,0,0.8)',
                                        shadowOffsetX: 0,
                                        shadowOffsetY: 0,
                                        shadowBlur: 20,
                                        borderWidth: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                },
                            }]
                        };
                        myEcharts.setOption(option);
                    }
                }
            }
        }
    })
}
export default install